﻿@{
    ViewBag.Title = "微信消息模拟测试工具";
    Layout = "~/Views/Shared/_Layout.cshtml";

    var nonce = "JeffreySu";
    var timestamp = DateTime.Now.Ticks.ToString();
    var echostr = DateTime.Now.Ticks.ToString();
    var token = ViewData["Token"] as string;
}
@section HeaderContent
{
    <style>
        .param {
            display: none;
        }

        .messageXmlArea {
            width: 100%;
        }

            .messageXmlArea textarea {
                width: 100%;
                height: 200px;
            }

        .paramAreaLeft {
            float: left;
            width: 45%;
            margin-right: 6%;
        }

        .paramArearight {
            width: 45%;
            float: left;
        }

        #requestType, #eventType {
            padding: 5px;
        }

        label.checkbox {
            line-height: 28px;
            padding-left: 85px;
            overflow: hidden;
        }

        #loadResult_Loading, #loadResult_Result {
            display: none;
        }
    </style>
    <script>
        $(function () {
            $('#requestType').change(checkRequestType);
            $('#eventType').change(checkEventType);
            $('#UseAsyncController').change(switchAsyncController);
            $('#TestConcurrence').change(switchTestConcurrenceRange);

            checkRequestType();
            checkEventType();
        });

        function checkRequestType() {
            var requestType = $('#requestType').val();
            var paramId = 'param' + requestType;
            $('div[id^=param]').hide();
            $('#' + paramId).show();
        }

        function checkEventType() {
            var requestType = $('#eventType').val();
            var eventId = 'event' + requestType;
            $('div[id^=event]').hide();
            $('#' + eventId).show();
        }

        function checkTestConcurrence() {
            return $('#TestConcurrence:checked').length > 0;
        }

        function sendMessage() {
            var url = $('#Url').val();
            var token = $('#Token').val();
            var requestType = $('#requestType').val();
            var eventType = $('#eventType').val();
            var testConcurrenceCount = $('#TestConcurrenceRange').val();
            var param = { url: url, token: token, requestType: requestType, testConcurrence: checkTestConcurrence(), testConcurrenceCount: testConcurrenceCount };
            var paramId = 'param' + requestType;
            var eventId = 'event' + eventType;
            var msgId = $('#txtMsgId').val();

            if (!msgId) {
                alert('MsgId必须填写！');
                return;
            }

            //设置参数
            if (requestType != 'Event') {
                $.each($('#' + paramId).find('input'), function (i, item) {
                    param[$(item).attr('name')] = $(item).val();
                });
            } else {
                param.eventType = eventType;
                $.each($('#' + eventId).find('input'), function (i, item) {
                    param[$(item).attr('name')] = $(item).val();
                });
            }
            param.MsgId = msgId;

            var txtResponseMessageXML = $('#responseMessageXML');
            var txtRequestMessageXML = $('#requestMessageXML');
            var loadResult_Loading = $('#loadResult_Loading');
            var loadResult_Result = $('#loadResult_Result');

            txtResponseMessageXML.html('载入中...');
            txtRequestMessageXML.html('载入中...');

            if (checkTestConcurrence()) {
                loadResult_Loading.show();
                loadResult_Result.hide();
            } else {
                loadResult_Loading.hide();
                loadResult_Result.hide();
            }

            $.post('@Url.Action("Index")', param, function (json) {
                txtResponseMessageXML.text(json.Result);
                loadResult_Loading.hide();
                if (json.Success) {
                    $('#loadTime').text(json.LoadTime);
                    if (checkTestConcurrence()) {
                        loadResult_Result.show();
                    }
                } else {
                    loadResult_Result.hide();
                }
            });

            $.post('@Url.Action("GetRequestMessageXml")', param, function (result) {
                txtRequestMessageXML.text(result);
            });

            $('#txtMsgId').val(parseInt($('#txtMsgId').val()) + 10000);
        }

        function switchAsyncController() {
            if ($('#UseAsyncController:checked').length > 0) {
                $('#Url').val('@Url.Action("Index", "WeixinAsync", null, "http", Request.Url.Host)');
            } else {
                $('#Url').val('@Url.Action("Index", "Weixin", null, "http", Request.Url.Host)');
            }
        }

        function switchTestConcurrenceRange() {
            if (checkTestConcurrence()) {
                $('#TestConcurrenceRange').show();
            } else {
                $('#TestConcurrenceRange').hide();
            }
        }
    </script>
}
<div class="catalog">
    <a href="@Url.Action("Index", "Menu")">自定义菜单设置工具</a>
    <a href="@Url.Action("Index", "SimulateTool")" class="active">消息模拟工具</a>
</div>
<div class="wrapper">
    <div class="form-control">
        <ul>
            <li>
                <label class="control-title">接口设置</label>
            </li>
            <li>
                <label class="control-label">URL:</label>
                @Html.TextBox("Url", Url.Action("Index", "Weixin", null, "http", Request.Url.Host), new { @class = "control-input" })
            </li>
            <li>
                <label class="checkbox">@Html.CheckBox("UseAsyncController", true)使用异步Controller</label>
            </li>
            <li>
                <label class="control-label">Token:</label>
                @Html.TextBox("Token", token, new { @class = "control-input" })
            </li>
            <li>
                <label class="control-title">发送参数</label>
            </li>
            <li>
                <label class="control-label">类型:</label>
                <select id="requestType" class="control-select">
                    <option value="Text">文本</option>
                    <option value="Location">地理位置</option>
                    <option value="Image">图片</option>
                    <option value="Voice">语音</option>
                    <option value="Video">视频</option>
                    @*<option value="Link">连接信息</option>*@
                    <option value="Event">事件推送</option>
                </select>
                @*<input class="control-input" type="text" />*@
            </li>
            <li>
                <label class="control-title">参数：</label>
                <br />
                <div id="paramText" class="param">
                    <label class="control-label">Content：</label><input name="Content" class="control-input" />
                </div>
                <div id="paramLocation" class="param">
                    <label class="control-label">Label：</label><input name="Label" class="control-input" /><br />
                    <label class="control-label">Location_X：</label><input name="Location_X" type="number" value="0" class="control-input" /><br />
                    <label class="control-label">Location_Y：</label><input name="Location_Y" type="number" value="0" class="control-input" /><br />
                    <label class="control-label">Scale：</label><input name="Scale" type="number" value="0" step="1" class="control-input" /><br />
                </div>
                <div id="paramImage" class="param">
                    <label class="control-label">PicUrl：</label><input name="PicUrl" class="control-input" /><br />
                </div>
                <div id="paramVoice" class="param">
                    <label class="control-label">Format：</label><input name="Format" value="arm" class="control-input" /><br />
                    <label class="control-label">Recognition：</label><input name="Recognition" class="control-input" /><br />
                </div>
                <div id="paramVideo" class="param">
                    <label class="control-label">MsgId：</label><input class="control-input" name="MsgId" type="number" value="@DateTime.Now.Ticks" step="1" /><br />
                    <label class="control-label">ThumbMediaId：</label><input name="ThumbMediaId" class="control-input" /><br />
                </div>
                @*<div id="paramLink" class="param"></div>*@
                <div id="paramEvent" class="param">
                    <label class="control-label">事件类型：</label><select id="eventType" class="control-select">
                        @*<option value="ENTER">进入会话</option>*@
                        <option value="LOCATION">地理位置</option>
                        <option value="subscribe">订阅</option>
                        <option value="unsubscribe">取消订阅</option>
                        <option value="CLICK">自定义菜单点击事件</option>
                        <option value="scan">二维码扫描</option>
                        <option value="VIEW">URL跳转</option>
                        <option value="MASSSENDJOBFINISH">事件推送群发结果</option>
                        <option value="TEMPLATESENDJOBFINISH">模板信息发送完成</option>
                        <option value="scancode_push">扫码推事件</option>
                        <option value="scancode_waitmsg">扫码推事件且弹出“消息接收中”提示框</option>
                        <option value="pic_sysphoto">弹出系统拍照发图</option>
                        <option value="pic_photo_or_album">弹出拍照或者相册发图</option>
                        <option value="pic_weixin">弹出微信相册发图器</option>
                        <option value="location_select">弹出地理位置选择器</option>
                    </select>
                    @*<div id="eventENTER" class="param"></div>*@
                    <div id="eventLOCATION" class="param">
                        <label class="control-label">Latitude：</label><input class="control-input" name="Event.Latitude" type="number" value="0" /><br />
                        <label class="control-label">Longitude：</label><input class="control-input" name="Event.Longitude" type="number" value="0" /><br />
                        <label class="control-label">Precision：</label><input class="control-input" name="Event.Precision" type="number" value="0" /><br />
                    </div>
                    <div id="eventsubscribe" class="param">
                        <label class="control-label">EventKey：</label><input name="Event.EventKey" class="control-input" /><br />
                    </div>
                    <div id="eventunsubscribe" class="param"></div>
                    <div id="eventCLICK" class="param">
                        <label class="control-label">EventKey：</label><input name="Event.EventKey" class="control-input" /><br />
                        <label class="control-label">Ticket：</label><input class="control-input" name="Event.Ticket" /><br />
                    </div>
                    <div id="eventscan" class="param">
                        <label class="control-label">EventKey：</label><input name="Event.EventKey" class="control-input" /><br />
                        <label class="control-label">Ticket：</label><input class="control-input" name="Event.Ticket" /><br />
                    </div>
                    <div id="eventVIEW" class="param">
                        <label class="control-label">EventKey：</label><input name="Event.EventKey" class="control-input" value="http://" /><br />
                    </div>
                    <div id="eventMASSSENDJOBFINISH" class="param">
                        <label class="control-label">ErrorCount：</label><input class="control-input" name="Event.ErrorCount" type="number" value="0" /><br />
                        <label class="control-label">FilterCount：</label><input class="control-input" name="Event.FilterCount" type="number" value="0" /><br />
                        <label class="control-label">SendCount：</label><input class="control-input" name="Event.SendCount" type="number" value="0" /><br />
                        <label class="control-label">Status：</label><input class="control-input" name="Event.Status" /><br />
                        <label class="control-label">TotalCount：</label><input class="control-input" name="Event.TotalCount" type="number" value="0" /><br />
                    </div>
                    <div id="eventTEMPLATESENDJOBFINISH" class="param">
                        <label class="control-label">MsgID：</label><input class="control-input" name="Event.MsgID" /><br />
                        <label class="control-label">Status：</label><input class="control-input" name="Event.Status" /><br />
                    </div>
                    <div id="eventscancode_push" class="param">
                        <label class="control-label">EventKey：</label><input class="control-input" name="Event.EventKey" /><br />
                        <label class="control-label">ScanResult：</label><input class="control-input" name="Event.ScanResult" /><br />
                        <label class="control-label">ScanType：</label><input class="control-input" name="Event.ScanType" /><br />
                    </div>
                    <div id="eventscancode_waitmsg" class="param">
                        <label class="control-label">EventKey：</label><input class="control-input" name="Event.EventKey" /><br />
                        <label class="control-label">ScanResult：</label><input class="control-input" name="Event.ScanResult" /><br />
                        <label class="control-label">ScanType：</label><input class="control-input" name="Event.ScanType" /><br />
                    </div>
                    <div id="eventpic_sysphoto" class="param">
                        <label class="control-label">EventKey：</label><input class="control-input" name="Event.EventKey" /><br />
                        <label class="control-label">Count：</label><input class="control-input" name="Event.Count" /><br />
                        <label class="control-label">PicMd5Sum：</label><input class="control-input" name="Event.PicMd5Sum" /><br />
                    </div>
                    <div id="eventpic_photo_or_album" class="param">
                        <label class="control-label">EventKey：</label><input class="control-input" name="Event.EventKey" /><br />
                        <label class="control-label">Count：</label><input class="control-input" name="Event.Count" /><br />
                        <label class="control-label">PicMd5Sum：</label><input class="control-input" name="Event.PicMd5Sum" /><br />
                    </div>
                    <div id="eventpic_weixin" class="param">
                        <label class="control-label">EventKey：</label><input class="control-input" name="Event.EventKey" /><br />
                        <label class="control-label">Count：</label><input class="control-input" name="Event.Count" /><br />
                        <label class="control-label">PicMd5Sum：</label><input class="control-input" name="Event.PicMd5Sum" /><br />
                    </div>
                    <div id="eventlocation_select" class="param">
                        <label class="control-label">EventKey：</label><input class="control-input" name="Event.EventKey" /><br />
                        <label class="control-label">Label：</label><input class="control-input" name="Event.Label" /><br />
                        <label class="control-label">Location_X：</label><input class="control-input" name="Event.Location_X" /><br />
                        <label class="control-label">Location_Y：</label><input class="control-input" name="Event.Location_Y" /><br />
                        <label class="control-label">Poiname：</label><input class="control-input" name="Event.Poiname" /><br />
                        <label class="control-label">Scale：</label><input class="control-input" name="Event.Scale" /><br />
                    </div>
                </div>
            </li>
            <li>
                <label class="control-label">MagId:</label>
                <input class="control-input" id="txtMsgId" name="MsgId" type="number" value="@DateTime.Now.Ticks" />
            </li>
            <li>
                <label class="checkbox">@Html.CheckBox("TestConcurrence", true)测试并发性能</label>
                <input id="TestConcurrenceRange" type="range" min="2" max="30" value="10" />
            </li>
            <li>
                <button class="control-btn" onclick="sendMessage()">提交</button>
            </li>
        </ul>
    </div>
    <div class="form-control">
        <ul>
            <li>
                <label class="control-title send">发送内容（根据参数自动生成）</label>
                <textarea class="control-text" id="requestMessageXML" readonly="readonly"></textarea>
            </li>
            <li>
                <label class="control-title send">接收内容</label>
                <textarea class="control-text" id="responseMessageXML"></textarea>
            </li>
            <li>
                <label class="control-title send" id="loadResult_Loading">模拟并发请求中……</label>
                <label class="control-title send" id="loadResult_Result">模拟并发响应时间：<span id="loadTime"></span> ms<br/>
                由于后台代理转发暂时没有使用异步请求，结果可能会受影响
                </label>
            </li>
            <li></li>
        </ul>
    </div>
    <div class="clear"></div>
</div>
